/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.global;

import cn.ac.iie.di.friend.JsonFriendSender.ClientPool;
import cn.ac.iie.di.tools.Configuration;
import cn.ac.iie.di.tools.JedisConnectionHandler;
import iie.mm.client.ClientAPI;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.dbcp.BasicDataSourceFactory;
import redis.clients.jedis.Jedis;

/**
 *
 * @author lenovo-pc
 */
public class GlobalParas {

    public static ArrayBlockingQueue<String> jsonQueue = new ArrayBlockingQueue(500);
    public static ArrayBlockingQueue<String> unzipQueue = new ArrayBlockingQueue(100);
    public static ArrayBlockingQueue<String> completeZipQueue = new ArrayBlockingQueue(100);
    public static ArrayBlockingQueue<Map> insertQueue = new ArrayBlockingQueue(100);
    public static ArrayBlockingQueue<Map> updateQueue = new ArrayBlockingQueue(100);
    public static ArrayBlockingQueue<String> retryQueue = new ArrayBlockingQueue(100);
    public static ArrayBlockingQueue<Map> mppQueue = new ArrayBlockingQueue(100);
    public static ArrayBlockingQueue<Map<String, String>> sendQueue = new ArrayBlockingQueue(100);

    public static ArrayBlockingQueue<Map> sendPYQQueue = new ArrayBlockingQueue(100);
    public static ArrayBlockingQueue<Map> sendCMDQueue = new ArrayBlockingQueue(100);
    public static ArrayBlockingQueue<Map> sendUSERQueue = new ArrayBlockingQueue(100);
    public static ArrayBlockingQueue<Map> sendMediaQueue = new ArrayBlockingQueue(100);

    public static String IP_PORT = null;

    public static String ZIP_DIR = null;//zip文件夹
    public static String DEC_DIR = null;//解压至文件夹
    public static String FINAL_DIR = null;//最后移动文件夹

    //redis配置
    public static String REDIS_URL = null;
    public static String REDIS_NAME = null;
    public static Integer REDIS_DBNUM = null;
    //多媒体接口配置
    public static String MEDIA_URL = null;
    public static String MEDIA_NAME = null;

    public static ClientAPI pcInfo = null;//多媒体接口
    public static JedisConnectionHandler connectionHandler = null;//redis连接池

    public static int POOL_MSG = 20;//发送MQ线程大小
    public static String TYPE_PYQ = null;//发送字段类型
    public static String MQ_PYQ = null;//MQ队列名
    public static String TYPE_CMD = null;//发送字段类型
    public static String MQ_CMD = null;//MQ队列名
    public static String TYPE_USER = null;//发送字段类型
    public static String MQ_USER = null;//MQ队列名
    public static String TYPE_MEDIA = null;//发送字段类型
    public static String MQ_MEDIA = null;//MQ队列名

    public static ClientPool pool;
    public static Jedis edis = null;
    public static Map<String, Integer> MEDIR_TYPE = null;

    static {
        try {
            MEDIR_TYPE = new HashMap<>();
            String[] medirtype = LoadProperties("MEDIR_TYPE").split("\\|");
            for (String s : medirtype) {
                MEDIR_TYPE.put(s.split("\\:")[0], Integer.valueOf(s.split("\\:")[1]));
            }
            pcInfo = new ClientAPI();
            //MQ端口号
            IP_PORT = LoadProperties("IP_PORT");

            //需要解压的文件夹
            ZIP_DIR = LoadProperties("ZIP_DIR");

            //解析文件夹
            DEC_DIR = LoadProperties("DEC_DIR");

            //最后存放原始文件的文件夹
            FINAL_DIR = LoadProperties("FINAL_DIR");

            TYPE_PYQ = LoadProperties("TYPE_PYQ");
            MQ_PYQ = LoadProperties("MQ_PYQ");
            TYPE_CMD = LoadProperties("TYPE_CMD");
            MQ_CMD = LoadProperties("MQ_CMD");
            TYPE_USER = LoadProperties("TYPE_USER");
            MQ_USER = LoadProperties("MQ_USER");
            TYPE_MEDIA = LoadProperties("TYPE_MEDIA");
            MQ_MEDIA = LoadProperties("MQ_MEDIA");

            //redis
            REDIS_URL = LoadProperties("REDIS_URL");
            REDIS_NAME = LoadProperties("REDIS_NAME");
            REDIS_DBNUM = Integer.valueOf(LoadProperties("REDIS_DBNUM"));

            //多媒体
            MEDIA_URL = LoadProperties("MEDIA_URL");
            MEDIA_NAME = LoadProperties("MEDIA_NAME");
            //多媒体接口初始化
            pcInfo.init(GlobalParas.MEDIA_URL, GlobalParas.MEDIA_NAME);
            connectionHandler = new JedisConnectionHandler(REDIS_URL, REDIS_NAME, REDIS_DBNUM);

        } catch (Exception ex) {
            Logger.getLogger(GlobalParas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static String LoadProperties(String str) {
        Configuration conf = Configuration.getConfiguration(ClassLoader.getSystemClassLoader().getResource("config.properties").getFile());
        return conf.getString(str, "");
    }

    public static HashMap<String, Object> Map() {
        HashMap map = new HashMap<String, Object>();
        for (String columntype : GlobalParas.LoadProperties("MAP").split("\\|")) {
            map.put(columntype.split("[:]")[0].toLowerCase(), columntype.split("[:]")[1].toLowerCase());
        }
        return map;
    }
}
